import os

import allure

from automation_api.base.base import BaseAPI
from automation_api.until.untils import Until


class LiteMail(BaseAPI):
    def __init__(self):
        # 读取配置文件
        yaml_data = self.get_data_info()
        self.base_url = yaml_data["base_url"]
        self.username = yaml_data["username"]["admin"]
        self.password = yaml_data["password"]["admin"]
        # 获取token
        self.token = self.get_token()["data"]["token"]


    def get_data_info(self):
        """
        拼接路径，读取yaml
        :return:
        """
        path = os.sep.join([Until.git_file_path("data/litemail.yaml")])
        return Until.git_yaml_path(path)

    @allure.step('获取token')
    def get_token(self):
        """
        登录获取token信息
        :return:
        """
        req_data = {
            "method": "POST",
            "url": self.base_url + "/auth/login",
            "json": {
                "username": self.username,
                "password": self.password,
            }
        }
        # 发起请求
        resp = self.send_request(req_data)
        return resp.json()


if __name__ == '__main__':
    ww = LiteMail()
    print(ww.token)